package com.gao.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

/**
 * 消费端限流
 *  1. 确保ack为手动确认
 *  2. 配置属性,prefetch = 1 ：表示消费端每次从mq拉去一条消息去消费，直到手动确认消费完毕后，才继续拉取下一条消息
 * @author gaofeng
 * @date 2022年09月08日 19:28
 */
@Component
public class QosListener implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        System.out.println("1.获取消息");
        System.out.println("2.处理业务逻辑");
//        3. 签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
